package responsibility.problematic;

/**
 * @Author: Doream
 * @Date: 2022/1/29 21:31
 */
// 抽象处理者
public abstract class Handler {
    protected final static int NUM_ONE = 1;
    protected final static int NUM_THREE = 3;
    protected final static int NUM_SEVEN = 7;
    private int numStrat;
    private int numEnd;

    // 上级领导(后继者)
    private Handler nextHandler;

    public Handler(int numStrat, int numEnd) {
        this.numStrat = numStrat;
        this.numEnd = numEnd;
    }

    public void setNextHandler(Handler nextHandler) {
        this.nextHandler = nextHandler;
    }

    // 各级领导的处理方法
    protected abstract void handlerLeaveRequest(LeaveRequest leaveRequest);

    // 提交请假条
    public final void submit(LeaveRequest leaveRequest){
        this.handlerLeaveRequest(leaveRequest);
        if (this.nextHandler != null && leaveRequest.getNum()>this.numEnd){
            this.nextHandler.submit(leaveRequest);
        }else {
            System.out.println("流程结束");
        }
    }
}
